#!usr/bin/env node

const Koa = require('koa');
     
const app = new Koa();

//中间件  middleware
////use:加载中间件
app.use((ctx,next)=>{
  ctx.body = 'hello world';//body是响应体
  next();//如果没有next，则下面的use不会执行
});

app.use((ctx,next)=>{
  const start = Date.now();
  next();
  const end = Date.now();
  console.log(`time:${end-start}ms`)
})

app.use((ctx,next)=>{
  console.log(`${ctx.method} ${ctx.path}`);
})

app.listen(3000);
console.log('hello koa')




